package com.deryun.tyl.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.deryun.tyl.bean.Contact;
import com.deryun.tyl.service.impl.ContactServiceImpl;

@Controller
@RequestMapping("contact")
public class ContactController {

	@Resource(name="contactServiceImpl")
	private ContactServiceImpl contactServiceImpl;
	
	@RequestMapping("/getAllContact")
	public List<Contact> getAllContact(){
		return contactServiceImpl.getAllContact();
	}
	
	@RequestMapping("/addContact")
	public String addContact(Contact contact){
		contactServiceImpl.addContact(contact);
		return "redirect:/ftoac/toLoadLxfs";
	}
	
	@RequestMapping("/deleteContact")
	public String deleteContact(int id){
		contactServiceImpl.deleteContact(id);
		return "redirect:/ftoac/toLoadLxfs";
	}
	
	@RequestMapping("/searchC")
	public String searchC(@RequestParam("key") String key,HttpServletRequest request){
		String keyt = "%"+key+"%";
		List<Contact> contacts = contactServiceImpl.searchC(keyt);
		request.setAttribute("message", contacts);
		return "civil_service/contact_information";
	}
}
